package com.lh.api.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.lh.api.dao.NoticeMapper;
import com.lh.api.service.NoticeService;
import com.lh.api.vo.NoticeVo;
import com.lh.common.entity.admin.Notice;
import com.lh.common.utils.PageUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements NoticeService {

    @Override
    public PageUtils<NoticeVo> getNoticeList(Map<String, Object> params, Integer pageNum, Integer pageSize) {
        if(pageNum != null && pageSize != null){
            PageHelper.startPage(pageNum, pageSize);
        }
        List<NoticeVo> noticeList = this.baseMapper.getNoticeList(params);
        for(NoticeVo noticeVo : noticeList){
            if(!StringUtils.isEmpty(noticeVo.getImg())){
                noticeVo.setImgList(Arrays.asList(noticeVo.getImg().split(",")));
            }
        }
        return  new PageUtils<>(noticeList);
    }
}
